package site.dao;

import java.sql.Connection;
import java.sql.SQLException;

import neoutil.CommonDao;
import neoutil.Page;
import site.entity.Organization;

public class OrganizationDao extends CommonDao<Organization, Long> {
	private String SQL_INSERT = "INSERT INTO organization(uuid, name, address, telephone, fax, email, contactPerson, description, visibility, entityStatus, entityDatetime) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

	public OrganizationDao(Connection connection) {
		super(Organization.class, connection);
	}

	public void save(Organization organization) throws SQLException {
		Object[] params = new Object[] { organization.getUuid(),
				organization.getName(), organization.getAddress(),
				organization.getTelephone(), organization.getFax(),
				organization.getEmail(), organization.getContactPerson(),
				organization.getDescription(), organization.getVisibility(),
				organization.getEntityStatus(),
				organization.getEntityDatetime() };

		execute(SQL_INSERT, params);
	}

	@Override
	public void deleteById(long id) throws SQLException {
		String sql = "DELETE FROM organization WHERE id=?";
		Object[] params = new Object[] { id };

		execute(sql, params);
	}

	public Page<Organization> getAllVisibleOrganizations(
			final Page<Organization> page) {
		String sql = "SELECT * FROM organization WHERE visibility="
				+ Organization.VISIBILITY_SHOW;
		return find(page, sql);
	}
}
